/**
 * window.sessionStorage封装，可以保存对象
 * 用法
 * import storage from 'libs/sessionStorage';
 * storage.set('a', {a: 1, b: 2});
 * storage.get('a'); // {a: 1, b: 2}
 * storage.remove('a');
 */

export default {
  get(key) {
    let res;
    try {
      res = JSON.parse(window.sessionStorage.getItem(key)) || '';
    } catch (e) {
      res = '';
    }
    return res;
  },
  set(key, value) {
    return window.sessionStorage.setItem(key, JSON.stringify(value));
  },
  remove(key) {
    return window.sessionStorage.removeItem(key);
  }
}